package cn.source.system.utils;

import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.jdbc.core.JdbcTemplate;

public class SpringFactoryUtil {

    /**
     * 注册一个bean
     *
     * @param beanName
     * @param obj
     */
    public static void registerBean(String beanName, Object obj) {
        //将数据源加入到Spring环境中
        DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) SpringUtil.getBeanFactory();
        if (beanFactory.containsBean(beanName)) {
            beanFactory.destroySingleton(beanName);//销毁bean
        }
        //重新注册
        beanFactory.registerSingleton(beanName, obj);
    }

}
